Imports IICModel.BusObjects.Mappers
Imports IICModel.ConversionObjects.Mappers
Imports IICModel.BusObjects
Imports IICModel.ConversionObjects

Namespace DataConbversionLogic
    Public Class PXSPeriodsConverter
        Inherits BaseDataConverter

        Protected Overrides Sub mapData(ByVal source As org.model.lib.Model.IModelObject, _
                                        ByRef destination As org.model.lib.Model.IModelObject)

            Dim s As PXS_PRDS = CType(source, PXS_PRDS)
            Dim d As Period = CType(destination, Period)

            d.IsOpen = False
            d.PeriodCode = s.CODE
            d.PeriodDate = DateSerial(CInt(s.YearVal), CInt(s.MonthVal), 1)
            d.DiplomaSuperTypeId = 4 '4 is hard coded cfa
            d.DataConversionSourceTable = getTableName()

        End Sub

        Protected Overrides Function getTableName() As String
            Return "PXS_PRDS"
        End Function

        Protected Overrides Sub instantiateMappers()

            Me.dataConvMapper = New PXS_PRDSDBMapper()
            Me.newdbMapper = New PeriodDBMapper

        End Sub

        Protected Overrides Function checkData(ByVal source As IModelObject, _
                                  ByVal destination As IModelObject) As Boolean

            Return Me.newdbMapper.findWhere("DiplomaSuperTypeId=4 and PeriodCode={0}", _
                                            CType(source, PXS_PRDS).CODE) Is Nothing

        End Function


    End Class
End Namespace